package com.leetcode.p200;

import com.bean.ListNode;
import com.utils.DataUtils;

public class Test203 {

    public ListNode removeElements(ListNode head, int val) {
        ListNode dummyNode = new ListNode();
        dummyNode.next = head;
        ListNode cur = dummyNode;

        while (cur.next != null) {
            if (cur.next.val == val) {
                cur.next = cur.next.next;
            } else {
                cur = cur.next;
            }
        }

        return dummyNode.next;
    }

    public static void main(String[] args) {
        Test203 test = new Test203();
//        ListNode head = DataUtils.getListNode(new int[]{3, 11, 7, 4, 9, 4, 9, 6, 2, 99});
        ListNode head = DataUtils.getListNode(new int[]{1, 4, 3, 3, 3, 2, 5, 2});
//        ListNode head = DataUtils.getListNode(new int[]{3, 11, 7, 4});
        DataUtils.printListNode(test.removeElements(head, 3));
    }
}
